package ar.edu.unicen.exa.oop.bbquery.model.forum.topic;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ar.edu.unicen.exa.oop.bbquery.model.forum.Post;

/**
 * LeafTopic is a topic that host a collection of posts.
 * 
 * @author nicolas
 */
@Entity
public class LeafTopic extends Topic implements Serializable {

	/**
     * 
     */
	private static final long serialVersionUID = -3854362022375753614L;

	private Post openingPost;

	private int views;

	private static Logger log = LoggerFactory.getLogger(LeafTopic.class);

	public LeafTopic(String description, int topicNumber, Post p, int views) {
		super(description, topicNumber);
		setOpeningPost(p);
		setViews(views);
		log.info("LeafTopic ( {} ) Created", p.getTitle());
	}

	public void setOpeningPost(Post openingPost) {
		this.openingPost = openingPost;
	}

	@OneToOne(cascade = CascadeType.ALL)
	@PrimaryKeyJoinColumn
	public Post getOpeningPost() {
		return openingPost;
	}

	public void setViews(int views) {
		this.views = views;
	}

	public int getViews() {
		return views;
	}

	/*
	 * @Override
	 * 
	 * @Column(insertable = false, updatable = false)
	 */
	/*
	 * @Override
	 * 
	 * @Transient public String getTitle() { if (openingPost == null) return "";
	 * return openingPost.getTitle(); }
	 * 
	 * @Override
	 * 
	 * @Transient public void setTitle(String title) { if (openingPost != null)
	 * { openingPost.setTitle(title); } }
	 */

}
